package cn.com.ylpw.web.order.service.impl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Random;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import cn.com.ylpw.web.order.service.LimitService;
import cn.com.ylpw.web.util.RestTemplateUtil;

@Service("limitService")
public class LimitServiceImpl implements LimitService {

	private final Log log = LogFactory.getLog(LimitServiceImpl.class);
	private final static Random rand = new Random();

	// + rand.nextInt(9999)
	@Override
	public String getLimit() throws HttpException, IOException {
		
		RestTemplate restTemplate = RestTemplateUtil.getInstance();
		String repXml="";
		try {
			ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://limit.228.cn/limit.html?"+rand.nextInt(9999), String.class);
			repXml = responseEntity.getBody();
		} catch (Exception e) {
			log.error("LimitServiceImpl发送http请求失败", e);
		}
		return repXml;
	}

}
